package collection;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class Test1 {
    public static void main(String[] args) {
        Collection<String> collection = new ArrayList<>();
        collection.add("ccc");
        collection.add("qqq");

        System.out.println(collection);

        System.out.println(collection.contains("ccc"));

        System.out.println(collection.size());

        for (Object o : collection.toArray())
            System.out.print(o + " ");
        System.out.println();

        collection.remove("qqq");
        System.out.println(collection);
    }


    @Test
    public void test1() {
        // add 和 addAll 的区别
        Collection collection = new ArrayList();

        collection.add(1);
        collection.add(2);
        collection.add(3);

        Collection c = new ArrayList();

        c.add(7);
        c.add(8);
        collection.addAll(c);
        collection.add(c);

        System.out.println(collection);

    }

    @Test
    public void testIterator() {
        // 迭代器Iterator的使用
        Collection<String> c = new ArrayList<>();
        c.add("aaa");
        c.add("bbb");
        c.add("qqq");

        Iterator<String> iterator = c.iterator();
        while (iterator.hasNext()) {
            String next = iterator.next();
            System.out.print(next + " ");
        }

    }
}
